package sg.java.concepts.passByValue;

/**
 * This class investigates the effects of passing an object as a reference to a
 * method, modifying the CONTENTS of the object, then checking from the caller
 * if the CONTENTS of the object is still intact.
 * 
 * <h3>Results:</h3>
 * <p>
 * Name initially set to: Oh Chin Boon
 * </p>
 * <p>
 * After calling modifyContents: Oh Chin Boon
 * </p>
 * 
 * @author Oh Chin Boon
 * 
 */
public class ObjectContentsPassByValueApp {
	private static void modifyObject(Bus bus) {
		bus.setName("SBS Transit");
	}

	public static void main(String args[]) {
		Bus bus;

		bus = new Bus();
		bus.setName("Trans Island Bus");

		System.out.println("Bus initially set to (hashcode): " + bus);
		System.out.println("Bus name: " + bus.getName());

		modifyObject(bus);

		System.out.println("After calling modifyObject (hashcode): " + bus);
		System.out.println("Bus name: " + bus.getName());
	}
}

/**
 * Demonstration class.
 * 
 * @author Oh Chin Boon
 * 
 */
class Bus {
	private String name;

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}
}